Skip to content

#4284 Support DI-backed composite projections#4285

Merged
jeremydmiller merged 1 commit intoJasperFx:masterfrom
erdtsieck:feature/4284-composite-projection-di
Apr 26, 2026
Merged

#4284 Support DI-backed composite projections#4285
jeremydmiller merged 1 commit intoJasperFx:masterfrom
erdtsieck:feature/4284-composite-projection-di

Conversation

@erdtsieck
Copy link
Copy Markdown
Contributor

Add support for registering composite projections that require application services (DI).

  • Introduce CompositeProjection.AddProjectionWithServices to register projections resolved from IServiceProvider, honoring ServiceLifetime (Transient treated as Scoped, Singleton uses a single instance).
  • Implement internal plumbing: CompositeProjection now accepts an IServiceProvider and propagates it to projections via ICompositeProjectionServiceSource; add CompositeProjectionWithServicesSource, CompositeScopedIProjectionSource, CompositeScopedIProjectionExecution, and ProjectionActivatingServiceProvider/Scope to create/execute projections within scoped service scopes.
  • Wire service provider attachment through ProjectionOptions.AttachServiceProvider and call it when building stores (MartenServiceCollectionExtensions and SecondaryStoreConfig) so projections registered in AddMarten can resolve DI services.
  • Add an integration test (Feature_4284_composite_projection_with_services) that verifies scoped services are available to composite projections and that projections produce expected documents.

This enables composite projections to depend on scoped/singleton services from the host DI container when registered through AddMarten.

Fixes #4284

Add support for registering composite projections that require application services (DI).

- Introduce CompositeProjection.AddProjectionWithServices<T> to register projections resolved from IServiceProvider, honoring ServiceLifetime (Transient treated as Scoped, Singleton uses a single instance).
- Implement internal plumbing: CompositeProjection now accepts an IServiceProvider and propagates it to projections via ICompositeProjectionServiceSource; add CompositeProjectionWithServicesSource, CompositeScopedIProjectionSource, CompositeScopedIProjectionExecution, and ProjectionActivatingServiceProvider/Scope to create/execute projections within scoped service scopes.
- Wire service provider attachment through ProjectionOptions.AttachServiceProvider and call it when building stores (MartenServiceCollectionExtensions and SecondaryStoreConfig) so projections registered in AddMarten can resolve DI services.
- Add an integration test (Feature_4284_composite_projection_with_services) that verifies scoped services are available to composite projections and that projections produce expected documents.

This enables composite projections to depend on scoped/singleton services from the host DI container when registered through AddMarten.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for DI-backed projections inside CompositeProjectionFor

2 participants